﻿<?php    
     $date = getdate();
    $strdate = $date['year'].'-'.$date['mon'].'-'.$date['mday'].'_'.
                $date['hours'].'-'.$date['minutes'].'-'.$date['seconds'];
    $fmtdate = $date['mday'].'/'.$date['mon'].'/'.$date['year'].' '.
                $date['hours'].':'.$date['minutes'].':'.$date['seconds'];
    
    //so dau la mscb- Admin- cac danh muc he thong
    $name='a'.$cb['User']['canbo_id'].'_'.$strdate;//date('Y-m-d_h-m-s');
  
 // ini_set('memory_limit','512M');
    $worksheets = '';
    
      
    // Sheet đầu tiên lưu thông tin của cán bộ
    $rows = $xls->row($xls->hcell('UID').$xls->hcell('CBID').$xls->hcell('Họ tên').$xls->hcell('Thời điểm tải về'));
    $rows .= $xls->row(
            $xls->cell($cb['User']['id']).
            $xls->cell($cb['User']['canbo_id']).
            $xls->cell($cb['Canbo']['HOTEN']).
            $xls->cell($fmtdate));
    $worksheets .= $xls->worksheet('ThongTin', $rows);    
   
   
    
    
    $rows = $xls->row($xls->hcell('id').$xls->hcell('tendv').
                            $xls->hcell('date_sua'));
    foreach ( $dvtinhs as $result ):   
    $cells = '';
       $cells .= $xls->Cell($result['dvtinhs']['id']);
       $cells .= $xls->Cell($result['dvtinhs']['tendv']);

       $cells .= $xls->Cell($result['dvtinhs']['date_sua']);
       $rows .= $xls->row($cells);

    endforeach; 
    $worksheets .= $xls->worksheet('dvtinhs',$rows);
    
    
    
    $rows = $xls->row($xls->hcell('id').$xls->hcell('trambvtv_id').
                            $xls->hcell('HOTEN').$xls->hcell('NGAYSINH').
                           
                            $xls->hcell('PHAI').
                            $xls->hcell('date_sua'));
  

     foreach ( $canbos as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['canbos']['id']);
        $cells .= $xls->Cell($result['canbos']['trambvtv_id']);
        $cells .= $xls->Cell($result['canbos']['HOTEN']);
        $cells .= $xls->Cell($result['canbos']['NGAYSINH']);
        $cells .= $xls->Cell($result['canbos']['PHAI']);
      
        $cells .= $xls->Cell($result['canbos']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('canbos',$rows);
     

     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_CC').
                            $xls->hcell('DCHI_CC').$xls->hcell('SDT_CC').
                           
                            $xls->hcell('date_sua'));
  

     foreach ( $chicucbvtvs as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['chicuc_bvtvs']['id']);
        $cells .= $xls->Cell($result['chicuc_bvtvs']['TEN_CC']);
        $cells .= $xls->Cell($result['chicuc_bvtvs']['DCHI_CC']);
        $cells .= $xls->Cell($result['chicuc_bvtvs']['SDT_CC']);
            
        $cells .= $xls->Cell($result['chicuc_bvtvs']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('chicucbvtvs',$rows);
        
    
             	 	 
           
     $rows = $xls->row($xls->hcell('id').$xls->hcell('DIEM').
                           
                            $xls->hcell('date_sua'));
     foreach ( $diemdts as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['diem_dts']['id']);
        $cells .= $xls->Cell($result['diem_dts']['DIEM']);
       
            
        $cells .= $xls->Cell($result['diem_dts']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('diemdts',$rows);
     
       
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_DT').
                            $xls->hcell('DIENGIAI').
                           
                            $xls->hcell('date_sua'));
  

     foreach ( $doituongs as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['doituongs']['id']);
        $cells .= $xls->Cell($result['doituongs']['TEN_DT']);
        $cells .= $xls->Cell($result['doituongs']['DIENGIAI']);
                    
        $cells .= $xls->Cell($result['doituongs']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('doituongs',$rows);
     	 
     
         
      $rows = $xls->row($xls->hcell('id').$xls->hcell('loai_dt_id').
                            $xls->hcell('doituong_id').
                           
                            $xls->hcell('date_sua'));
  

     foreach ( $dtloaidts as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['dt_loaidts']['id']);
        $cells .= $xls->Cell($result['dt_loaidts']['loai_dt_id']);
        $cells .= $xls->Cell($result['dt_loaidts']['doituong_id']);
                    
        $cells .= $xls->Cell($result['dt_loaidts']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('dtloaidts',$rows);
     	 	
     
           
            
            
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_GL').
                            $xls->hcell('TGST').
                             $xls->hcell('KNCC').
                           
                            $xls->hcell('date_sua'));
  

     foreach ( $giongluas as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['giongluas']['id']);
        $cells .= $xls->Cell($result['giongluas']['TEN_GL']);
        $cells .= $xls->Cell($result['giongluas']['TGST']);
        $cells .= $xls->Cell($result['giongluas']['KNCC']);                    
        $cells .= $xls->Cell($result['giongluas']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('giongluas',$rows);
   
     
     $rows = $xls->row($xls->hcell('id').$xls->hcell('hoatchat_id').
                            $xls->hcell('thuoc_id').
                                                      
                            $xls->hcell('date_sua'));
     
   
            
     foreach ( $hcthuocs as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['hc_thuocs']['id']);
        $cells .= $xls->Cell($result['hc_thuocs']['hoatchat_id']);
        $cells .= $xls->Cell($result['hc_thuocs']['thuoc_id']);
                      
        $cells .= $xls->Cell($result['hc_thuocs']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('hcthuocs',$rows);
     
     
     $rows = $xls->row($xls->hcell('id').$xls->hcell('ten_hc').
                            $xls->hcell('ghichu').
                                                      
                            $xls->hcell('date_sua'));
  

     
     foreach ( $hoatchats as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['hoatchats']['id']);
        $cells .= $xls->Cell($result['hoatchats']['ten_hc']);
        $cells .= $xls->Cell($result['hoatchats']['ghichu']);
                      
        $cells .= $xls->Cell($result['hoatchats']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('hoatchats',$rows);
      	 	
     
            
      $rows = $xls->row($xls->hcell('id').$xls->hcell('tinh_id').
                            $xls->hcell('TEN_H').
                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $huyens as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['huyens']['id']);
        $cells .= $xls->Cell($result['huyens']['tinh_id']);
        $cells .= $xls->Cell($result['huyens']['TEN_H']);
                      
        $cells .= $xls->Cell($result['huyens']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('huyens',$rows);
      	
     
           
      $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_LOAI').
                        
                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $loaidts as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['loai_dts']['id']);
        $cells .= $xls->Cell($result['loai_dts']['TEN_LOAI']);                     
        $cells .= $xls->Cell($result['loai_dts']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('loaidts',$rows);
      	
        
        
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_LP').
                            $xls->hcell('CONGDUNG_LP').                                                      
                            $xls->hcell('date_sua'));
    	 

     foreach ( $loaiphans as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['loaiphans']['id']);
        $cells .= $xls->Cell($result['loaiphans']['TEN_LP']);
        $cells .= $xls->Cell($result['loaiphans']['CONGDUNG_LP']);           
                       
        $cells .= $xls->Cell($result['loaiphans']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('loaiphans',$rows);
     
          
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_MUA').
                        
                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $muavues as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['mua_vues']['id']);
        $cells .= $xls->Cell($result['mua_vues']['TEN_MUA']);                     
        $cells .= $xls->Cell($result['mua_vues']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('muavues',$rows);
     
     
          
     $rows = $xls->row($xls->hcell('id').$xls->hcell('NAM').
                        
                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $nams as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['nams']['id']);
        $cells .= $xls->Cell($result['nams']['NAM']);                     
        $cells .= $xls->Cell($result['nams']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('nams',$rows);
     
  
  
      
     $rows = $xls->row($xls->hcell('id').$xls->hcell('loai_dt_id').
        $xls->hcell('DG_ND').$xls->hcell('GHICHU_ND').
        $xls->hcell('DVT_ND').     
        $xls->hcell('date_sua'));
  

     foreach ( $nddts as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['nd_dts']['id']);
        $cells .= $xls->Cell($result['nd_dts']['loai_dt_id']);
         $cells .= $xls->Cell($result['nd_dts']['DG_ND']); 
          $cells .= $xls->Cell($result['nd_dts']['GHICHU_ND']); 
           $cells .= $xls->Cell($result['nd_dts']['DVT_ND']);
           $cells .= $xls->Cell($result['nd_dts']['dvtinh_id']);                      
        $cells .= $xls->Cell($result['nd_dts']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('nddts',$rows);
      	 	 	   
     
     
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_NSS').
                                                                               
                            $xls->hcell('date_sua'));
  

     foreach ( $nsses as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['nsses']['id']);
        $cells .= $xls->Cell($result['nsses']['TEN_NSS']);
                           
        $cells .= $xls->Cell($result['nsses']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('nsses',$rows);
     
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_TS').
                            $xls->hcell('DVT_TS').
                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $thongsos as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['thongsos']['id']);
        $cells .= $xls->Cell($result['thongsos']['TEN_TS']);
        $cells .= $xls->Cell($result['thongsos']['DVT_TS']);                        
        $cells .= $xls->Cell($result['thongsos']['date_sua']);
         $cells .= $xls->Cell($result['thongsos']['dvtinh_id']);   
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('thongsos',$rows);
      	


    $rows = $xls->row($xls->hcell('id').$xls->hcell('gocthuoc_id').
                            $xls->hcell('TEN_THUOC').
                             $xls->hcell('CONGDUNG').
                                                      
                            $xls->hcell('date_sua'));
  
 	 	
     foreach ( $thuocs as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['thuocs']['id']);
        $cells .= $xls->Cell($result['thuocs']['gocthuoc_id']);
        $cells .= $xls->Cell($result['thuocs']['TEN_THUOC']);
        $cells .= $xls->Cell($result['thuocs']['CONGDUNG']);                          
        $cells .= $xls->Cell($result['thuocs']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('thuocs',$rows);
     
          
     $rows = $xls->row($xls->hcell('id').$xls->hcell('TEN_T').
                       
                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $tinhs as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['tinhs']['id']);
        $cells .= $xls->Cell($result['tinhs']['TEN_T']);
                    
        $cells .= $xls->Cell($result['tinhs']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('tinhs',$rows);
     
           
            
     $rows = $xls->row($xls->hcell('id').$xls->hcell('chicuc_bvtv_id').
                       $xls->hcell('TEN_TR').$xls->hcell('DCHI_TR').
                        $xls->hcell('SDT_TR').$xls->hcell('huyen_id').                                                      
                            $xls->hcell('date_sua'));
  

     foreach ( $trambvtvs as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['trambvtvs']['id']);
        $cells .= $xls->Cell($result['trambvtvs']['chicuc_bvtv_id']);
        $cells .= $xls->Cell($result['trambvtvs']['TEN_TR']);
                    
        $cells .= $xls->Cell($result['trambvtvs']['DCHI_TR']);
        $cells .= $xls->Cell($result['trambvtvs']['SDT_TR']);
        $cells .= $xls->Cell($result['trambvtvs']['huyen_id']);
        $cells .= $xls->Cell($result['trambvtvs']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('trambvtvs',$rows);
     
     
      	 	 	 	
            
     
     
   
     $rows = $xls->row($xls->hcell('id').$xls->hcell('USERNAME').
                       $xls->hcell('PASSWORD').$xls->hcell('canbo_id').
                        $xls->hcell('ROLE').                                                    
                            $xls->hcell('date_sua'));
  

     foreach ( $users as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['users']['id']);
        $cells .= $xls->Cell($result['users']['USERNAME']);
        $cells .= $xls->Cell($result['users']['PASSWORD']);
                    
        $cells .= $xls->Cell($result['users']['canbo_id']);
        $cells .= $xls->Cell($result['users']['ROLE']);
       
        $cells .= $xls->Cell($result['users']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('users',$rows);
     
           
      $rows = $xls->row($xls->hcell('id').$xls->hcell('huyen_id').
                       $xls->hcell('TEN_X').                                                  
                            $xls->hcell('date_sua'));
  

     foreach ( $xas as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['xas']['id']);
        $cells .= $xls->Cell($result['xas']['huyen_id']);
        $cells .= $xls->Cell($result['xas']['TEN_X']);
                    
       
       
        $cells .= $xls->Cell($result['xas']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('xas',$rows);
      	
            
    	 	 	         
     
     
    // If you print the output to the screen set the proper headers
    $xls->setHeader($name);
    echo $xls->workbook($worksheets);
   // $data = $xls->workbook($worksheets); 
//    
//    $encData = $cryptastic->encrypt($data, true);
//    if($encData === false){
//        $session->setFlash('Lỗi mã hóa dữ liệu');
//        $this->redirect(array('controller'=>'bks','action'=>'index'));
//    }else{
//        echo $encData;
//    }
//   
?> 